package day_2022_9_to_12.Day;

import java.util.Deque;
import java.util.LinkedList;

/**
 * @author haomin
 * @date 2022/10/18 22:15
 **/
public class Day46_4_Num230_KthSmallest {
    class Solution {
        public int kthSmallest(TreeNode root, int k) {
            if(root == null) return 0;
            Deque<TreeNode> stack = new LinkedList<>();
            while(root != null || !stack.isEmpty()){
                while(root != null) {
                    stack.push(root);
                    root = root.left;
                }
                root = stack.pop();
                --k;
                if(k == 0) {break;}
                root = root.right;
            }
            return root.val;
        }
    }
}